package com.swap.quartz.job;

import com.swap.quartz.job.jobs.SwapHandJob;
import com.swap.quartz.job.jobs.SwapRemoveHandlerJob;
import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class JobQuartzConfig {

    @Bean
    public Trigger swapAutoJob() {
        return TriggerBuilder.newTrigger().
                withIdentity("swapAutoJob", "snmp-group1").
                withSchedule(CronScheduleBuilder.cronSchedule("0 0 */2 * * ?"))
                .forJob(swapHandlerJob())
                .build();
    }

    @Bean
    public Trigger autoRemoveJob() {
        return TriggerBuilder.newTrigger().
                withIdentity("autoRemoveJob", "snmp-group2").
                withSchedule(CronScheduleBuilder.cronSchedule("0 0 1 1 * ?"))
                .forJob(swapRemoveHandlerJob())
                .build();
    }

    /**
     * 默认调度（每过2小时触发）
     *
     * @return
     */
    @Bean
    public JobDetail swapHandlerJob() {
        return JobBuilder.newJob(SwapHandJob.class).storeDurably().build();
    }

    /**
     * 默认调度（每1个月触发一次）
     *
     * @return
     */
    @Bean
    public JobDetail swapRemoveHandlerJob() {
        return JobBuilder.newJob(SwapRemoveHandlerJob.class).storeDurably().build();
    }
}
